#cmake file for project simplemq-cpp
#author:guyadong
#created:2020/04/03
##! 用于velrelcm.sh 的 变量搜索正则表达式, 不要轻易修改
##! @PRJNAME_REG@          (project\s*\(\s*)([[:alnum:]-]+)(\s+.*\))
##! @VERSION_REG@          (project\s*\(\s*[[:alnum:]-]+\s+VERSION\s+)(\S*)(.*\))
##! @DESC_REG@             (set\s*\(\s*SIMPLEMQ_CPP_VER_DESC\s+)(\S*)?(\s*\))
##! @SNAPSHOT_REG@         (project\s*\(\s*[[:alnum:]-]+\s+VERSION\s+[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)(\.1)?(.*\))
##! @BEANCH_REG@           (set\s*\(\s*SIMPLEMQ_CPP_SCM_BRANCH\s+)(\S*)?(\s*\))
##! @COMMIT_REG@           (set\s*\(\s*SIMPLEMQ_CPP_SCM_COMMIT\s+)(\S*)?(\s*\))
##! 用于头文件(header)中搜索版本定义的正则表达
##! @H_VERSION_MAJOR_REG@  (#define\s+SIMPLEMQ_CPP_VERSION_MAJOR\s+)(\S+)(\s*)
##! @H_VERSION_MINOR_REG@  (#define\s+SIMPLEMQ_CPP_VERSION_MINOR\s+)(\S+)(\s*)
##! @H_VERSION_PATCH_REG@  (#define\s+SIMPLEMQ_CPP_VERSION_PATCH\s+)(\S+)(\s*)
##! @H_VERSION_SNAPSHOT_REG@  (#define\s+SIMPLEMQ_CPP_VERSION_SNAPSHOT)(\s+\S+)(\s*)
cmake_minimum_required( VERSION 3.8 )
if(POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif()
# 3.0以上版本才允许使用VERSION option
project(simplemq-cpp VERSION 0.0.2.1 LANGUAGES CXX)
#判断编译类型和版本是否满足编译要求
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 _cxx11_enable)
if(NOT _cxx11_enable)
	message(FATAL_ERROR "Compiler not supported C++ 11 standard")
endif()
unset(_cxx11_enable)
# 要求编译器支持C++11
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
	#关闭C4819警告
	add_definitions("/wd4819")		
	message(STATUS "optional:/wd4819")
	#关闭CRT_SECURE警告
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	message(STATUS "optional:-D_CRT_SECURE_NO_WARNINGS")
endif(MSVC)
# 在支持层次工程组织的IDE(MSVC)中使用"FOLDER"属性定义的文件夹名称来组织项目
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
####simplemq库####
# 定义库名
set(SMQ_LIBNAME simplemq)
# 定义包名(find_package)
set(SMQ_PKGNAME simplemq) 

if(CMAKE_COMPILER_IS_GNUCXX)
  # 检查GNU编译是否支持 -Wa,-mbig-obj 
  include(CheckCXXCompilerFlag)
  check_cxx_compiler_flag("-Wa,-mbig-obj" GNU_BIG_OBJ_FLAG_ENABLE)
  message(STATUS GNU_BIG_OBJ_FLAG_ENABLE=${GNU_BIG_OBJ_FLAG_ENABLE})
endif()
##############设置目标文件生成位置#####################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
# define LIBRARY_INSTALL_DIR INCLUDE_INSTALL_DIR CONFIG_INSTALL_DIR
set (LIBRARY_INSTALL_DIR lib)
set (INCLUDE_INSTALL_DIR include)

find_package(common_source_cpp REQUIRED)

# 创建 INTERFACE target
add_library(${SMQ_LIBNAME} INTERFACE )
message(STATUS "target ${SMQ_LIBNAME}")
target_include_directories (${SMQ_LIBNAME} INTERFACE "$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")
target_compile_definitions(${SMQ_LIBNAME} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>)
target_link_libraries(${SMQ_LIBNAME} INTERFACE common_source_cpp::common_source_cpp $<$<PLATFORM_ID:Android>:log> $<$<PLATFORM_ID:Linux>:-pthread -ldl>)

add_library(${SMQ_LIBNAME}::${SMQ_LIBNAME} ALIAS ${SMQ_LIBNAME})
add_subdirectory( examples )